import { DependencyContainer } from "tsyringe";
import { MongoClient, Db } from 'mongodb'
export interface MongoHandler<T> {
    (db: Db): Promise<T>;
}
export const useMongo = async <T>(injector: DependencyContainer, handler: MongoHandler<T>): Promise<T> => {
    const url = `mongodb://cloud:123qwe@60.204.248.43:27017/`
    const dbName: string = `cloud`
    const client = new MongoClient(url, { useBigInt64: true })
    await client.connect();
    const db = client.db(dbName)
    const res = await handler(db);
    await client.close()
    return res;
}
export default useMongo;
